home *** CD-ROM | disk | FTP | other *** search
- Path: tech.cftnet.com!not-for-mail
- From: wcowley@cftnet.com (Wes Cowley)
- Newsgroups: comp.windows.x.motif,comp.lang.c++
- Subject: Re: MOTIF Callbacks, C++ Member Functions - SOLVED
- Followup-To: comp.windows.x.motif,comp.lang.c++
- Date: 20 Feb 1996 11:02:59 GMT
- Organization: CFTnet
- Distribution: inet
- Message-ID: <4gc9p3$s7s@tech.cftnet.com>
- References: <4f6oau$c4m@knot.queensu.ca> <4f9fbo$7ju@news1.halcyon.com> <4gbf05$6d8@rex.sfe.com.au>
- NNTP-Posting-Host: ppp244_4.cftnet.com
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
- Paul Hatchman (paul@sfe.com.au) wrote:
- : danubius@chinook.halcyon.com () writes:
- :
- : >Wintermute <3mal5@qlink.queensu.ca> wrote:
- : >>
- : >>The solution was to declare a static member function which is used as a
- : >>callback. Since it is static, there is no 'this' pointer, and it works
- : >>fine. To access the particular class instance, pass the 'this' pointer
- : >>as client data when installing the callback, and it will be available
- : >>when the static member function is called back.
- :
- : >Which is exactly the method Doug Young uses in his book on Motif with
- : >C++.
- :
- : >Joe
- :
- : I dont think there are any guarantees that a compiler will give static
- : functions "C" style linkage. It works with every compiler I have tried,
- : but I dont believe it is guaranteed to be portable.
- :
- : Can someone give an authorative answer on this?
- :
- : - Paul
-
- Static member functions don't get C linkage. If they did it wouldn't be
- possible to overload them. Using static member functions for callbacks
- where a C function is expected works because (in every environment I've
- seen) the difference between C and C++ linkage is in type safety, not in
- the parameter passing conventions. Because the actual linkage between the
- callback and the server code is done at runtime, name mangling doesn't
- matter and the argument types can't be checked. Given that the parameters
- are expected to be the same order and same size on both sides of the
- call, it doesn't matter that the callback function actually has C++ linkage:
- it will work.
-
- Somewhere, somebody's going to find a machine where that assumption doesn't
- hold true. I imagine there's a fair amount of existing code that won't
- run on it :)
-
- Wes
-